package c.e.a.c.x;

import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.RippleDrawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.Spinner;
import b.i.k.o;
import c.e.a.c.t.j;
import com.google.android.material.internal.CheckableImageButton;
import com.google.android.material.textfield.TextInputLayout;
import com.google.android.material.textfield.TextInputLayout.g;
import java.util.Objects;
import java.util.WeakHashMap;

/* compiled from: DropdownMenuEndIconDelegate */
public class h extends m {
    public final TextWatcher d = new a();
    public final OnFocusChangeListener e = new b();
    public final com.google.android.material.textfield.TextInputLayout.e f = new c(this.a);
    public final com.google.android.material.textfield.TextInputLayout.f g = new d();
    @SuppressLint({"ClickableViewAccessibility"})
    public final g h = new e();
    public boolean i = false;
    public boolean j = false;
    public long k = Long.MAX_VALUE;
    public StateListDrawable l;
    public c.e.a.c.t.g m;
    public AccessibilityManager n;
    public ValueAnimator o;
    public ValueAnimator p;

    /* compiled from: DropdownMenuEndIconDelegate */
    public class a implements TextWatcher {

        /* compiled from: DropdownMenuEndIconDelegate */
        public class a implements Runnable {
            public final /* synthetic */ AutoCompleteTextView a;

            public a(AutoCompleteTextView autoCompleteTextView) {
                this.a = autoCompleteTextView;
            }

            public void run() {
                boolean isPopupShowing = this.a.isPopupShowing();
                h.f(h.this, isPopupShowing);
                h.this.i = isPopupShowing;
            }
        }

        public void afterTextChanged(Editable editable) {
            h hVar = h.this;
            AutoCompleteTextView e = h.e(hVar, hVar.a.getEditText());
            e.post(new a(e));
        }

        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }
    }

    /* compiled from: DropdownMenuEndIconDelegate */
    public class b implements OnFocusChangeListener {
        public void onFocusChange(View view, boolean z) {
            h.this.a.setEndIconActivated(z);
            if (!z) {
                h.f(h.this, false);
                h.this.i = false;
            }
        }
    }

    /* compiled from: DropdownMenuEndIconDelegate */
    public class f implements OnClickListener {
        public void onClick(View view) {
            h.g(h.this, (AutoCompleteTextView) h.this.a.getEditText());
        }
    }

    /* compiled from: DropdownMenuEndIconDelegate */
    public class d implements com.google.android.material.textfield.TextInputLayout.f {
        public void a(TextInputLayout textInputLayout) {
            AutoCompleteTextView e = h.e(h.this, textInputLayout.getEditText());
            h hVar = h.this;
            int boxBackgroundMode = hVar.a.getBoxBackgroundMode();
            if (boxBackgroundMode == 2) {
                e.setDropDownBackgroundDrawable(hVar.m);
            } else if (boxBackgroundMode == 1) {
                e.setDropDownBackgroundDrawable(hVar.l);
            }
            hVar = h.this;
            Objects.requireNonNull(hVar);
            if (e.getKeyListener() == null) {
                boxBackgroundMode = hVar.a.getBoxBackgroundMode();
                c.e.a.c.t.g boxBackground = hVar.a.getBoxBackground();
                int i = c.e.a.c.a.i(e, 2130968776);
                r8 = new int[2][];
                r8[0] = new int[]{16842919};
                r8[1] = new int[0];
                int i2;
                WeakHashMap weakHashMap;
                if (boxBackgroundMode == 2) {
                    i2 = c.e.a.c.a.i(e, 2130968791);
                    c.e.a.c.t.g gVar = new c.e.a.c.t.g(boxBackground.a.a);
                    i = c.e.a.c.a.n(i, i2, 0.1f);
                    gVar.p(new ColorStateList(r8, new int[]{i, 0}));
                    gVar.setTint(i2);
                    ColorStateList colorStateList = new ColorStateList(r8, new int[]{i, i2});
                    c.e.a.c.t.g gVar2 = new c.e.a.c.t.g(boxBackground.a.a);
                    gVar2.setTint(-1);
                    RippleDrawable rippleDrawable = new RippleDrawable(colorStateList, gVar, gVar2);
                    LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{rippleDrawable, boxBackground});
                    weakHashMap = o.a;
                    e.setBackground(layerDrawable);
                } else if (boxBackgroundMode == 1) {
                    i2 = hVar.a.getBoxBackgroundColor();
                    RippleDrawable rippleDrawable2 = new RippleDrawable(new ColorStateList(r8, new int[]{c.e.a.c.a.n(i, i2, 0.1f), i2}), boxBackground, boxBackground);
                    weakHashMap = o.a;
                    e.setBackground(rippleDrawable2);
                }
            }
            hVar = h.this;
            Objects.requireNonNull(hVar);
            e.setOnTouchListener(new j(hVar, e));
            e.setOnFocusChangeListener(hVar.e);
            e.setOnDismissListener(new k(hVar));
            e.setThreshold(0);
            e.removeTextChangedListener(h.this.d);
            e.addTextChangedListener(h.this.d);
            textInputLayout.setEndIconCheckable(true);
            textInputLayout.setErrorIconDrawable(null);
            textInputLayout.setTextInputAccessibilityDelegate(h.this.f);
            textInputLayout.setEndIconVisible(true);
        }
    }

    /* compiled from: DropdownMenuEndIconDelegate */
    public class e implements g {
        public void a(TextInputLayout textInputLayout, int i) {
            AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) textInputLayout.getEditText();
            if (autoCompleteTextView != null && i == 3) {
                autoCompleteTextView.removeTextChangedListener(h.this.d);
                if (autoCompleteTextView.getOnFocusChangeListener() == h.this.e) {
                    autoCompleteTextView.setOnFocusChangeListener(null);
                }
                autoCompleteTextView.setOnTouchListener(null);
                autoCompleteTextView.setOnDismissListener(null);
            }
        }
    }

    /* compiled from: DropdownMenuEndIconDelegate */
    public class c extends com.google.android.material.textfield.TextInputLayout.e {
        public c(TextInputLayout textInputLayout) {
            super(textInputLayout);
        }

        public void d(View view, b.i.k.y.b bVar) {
            boolean isShowingHintText;
            super.d(view, bVar);
            if (h.this.a.getEditText().getKeyListener() == null) {
                bVar.a.setClassName(Spinner.class.getName());
            }
            if (VERSION.SDK_INT >= 26) {
                isShowingHintText = bVar.a.isShowingHintText();
            } else {
                Bundle f = bVar.f();
                isShowingHintText = f != null && (f.getInt("androidx.view.accessibility.AccessibilityNodeInfoCompat.BOOLEAN_PROPERTY_KEY", 0) & 4) == 4;
            }
            if (isShowingHintText) {
                bVar.k(null);
            }
        }

        public void e(View view, AccessibilityEvent accessibilityEvent) {
            this.a.onPopulateAccessibilityEvent(view, accessibilityEvent);
            h hVar = h.this;
            AutoCompleteTextView e = h.e(hVar, hVar.a.getEditText());
            if (accessibilityEvent.getEventType() == 1 && h.this.n.isTouchExplorationEnabled()) {
                h.g(h.this, e);
            }
        }
    }

    public h(TextInputLayout textInputLayout) {
        super(textInputLayout);
    }

    public static AutoCompleteTextView e(h hVar, EditText editText) {
        Objects.requireNonNull(hVar);
        if (editText instanceof AutoCompleteTextView) {
            return (AutoCompleteTextView) editText;
        }
        throw new RuntimeException("EditText needs to be an AutoCompleteTextView if an Exposed Dropdown Menu is being used.");
    }

    public static void f(h hVar, boolean z) {
        if (hVar.j != z) {
            hVar.j = z;
            hVar.p.cancel();
            hVar.o.start();
        }
    }

    public static void g(h hVar, AutoCompleteTextView autoCompleteTextView) {
        Objects.requireNonNull(hVar);
        if (autoCompleteTextView != null) {
            if (hVar.i()) {
                hVar.i = false;
            }
            if (hVar.i) {
                hVar.i = false;
                return;
            }
            boolean z = hVar.j;
            boolean z2 = z ^ 1;
            if (z != z2) {
                hVar.j = z2;
                hVar.p.cancel();
                hVar.o.start();
            }
            if (hVar.j) {
                autoCompleteTextView.requestFocus();
                autoCompleteTextView.showDropDown();
                return;
            }
            autoCompleteTextView.dismissDropDown();
        }
    }

    public void a() {
        float dimensionPixelOffset = (float) this.b.getResources().getDimensionPixelOffset(2131165473);
        float dimensionPixelOffset2 = (float) this.b.getResources().getDimensionPixelOffset(2131165431);
        int dimensionPixelOffset3 = this.b.getResources().getDimensionPixelOffset(2131165433);
        c.e.a.c.t.g h = h(dimensionPixelOffset, dimensionPixelOffset, dimensionPixelOffset2, dimensionPixelOffset3);
        c.e.a.c.t.g h2 = h(0.0f, dimensionPixelOffset, dimensionPixelOffset2, dimensionPixelOffset3);
        this.m = h;
        StateListDrawable stateListDrawable = new StateListDrawable();
        this.l = stateListDrawable;
        stateListDrawable.addState(new int[]{16842922}, h);
        this.l.addState(new int[0], h2);
        this.a.setEndIconDrawable(b.b.d.a.a.b(this.b, 2131231139));
        TextInputLayout textInputLayout = this.a;
        textInputLayout.setEndIconContentDescription(textInputLayout.getResources().getText(2131689833));
        this.a.setEndIconOnClickListener(new f());
        this.a.a(this.g);
        textInputLayout = this.a;
        textInputLayout.g0.add(this.h);
        ValueAnimator ofFloat = ValueAnimator.ofFloat(new float[]{0.0f, 1.0f});
        TimeInterpolator timeInterpolator = c.e.a.c.c.a.a;
        ofFloat.setInterpolator(timeInterpolator);
        ofFloat.setDuration((long) 67);
        ofFloat.addUpdateListener(new i(this));
        this.p = ofFloat;
        ValueAnimator ofFloat2 = ValueAnimator.ofFloat(new float[]{1.0f, 0.0f});
        ofFloat2.setInterpolator(timeInterpolator);
        ofFloat2.setDuration((long) 50);
        ofFloat2.addUpdateListener(new i(this));
        this.o = ofFloat2;
        ofFloat2.addListener(new l(this));
        CheckableImageButton checkableImageButton = this.c;
        WeakHashMap weakHashMap = o.a;
        checkableImageButton.setImportantForAccessibility(2);
        this.n = (AccessibilityManager) this.b.getSystemService("accessibility");
    }

    public boolean b(int i) {
        return i != 0;
    }

    public boolean d() {
        return true;
    }

    public final c.e.a.c.t.g h(float f, float f2, float f3, int i) {
        c.e.a.c.t.j.b bVar = new c.e.a.c.t.j.b();
        bVar.e = new c.e.a.c.t.a(f);
        bVar.f = new c.e.a.c.t.a(f);
        bVar.h = new c.e.a.c.t.a(f2);
        bVar.g = new c.e.a.c.t.a(f2);
        j a = bVar.a();
        Context context = this.b;
        String str = c.e.a.c.t.g.w;
        int u = c.e.a.c.a.u(context, 2130968791, c.e.a.c.t.g.class.getSimpleName());
        c.e.a.c.t.g gVar = new c.e.a.c.t.g();
        gVar.a.b = new c.e.a.c.m.a(context);
        gVar.w();
        gVar.p(ColorStateList.valueOf(u));
        c.e.a.c.t.g.b bVar2 = gVar.a;
        if (bVar2.o != f3) {
            bVar2.o = f3;
            gVar.w();
        }
        gVar.a.a = a;
        gVar.invalidateSelf();
        c.e.a.c.t.g.b bVar3 = gVar.a;
        if (bVar3.i == null) {
            bVar3.i = new Rect();
        }
        gVar.a.i.set(0, i, 0, i);
        gVar.invalidateSelf();
        return gVar;
    }

    public final boolean i() {
        long currentTimeMillis = System.currentTimeMillis() - this.k;
        return currentTimeMillis < 0 || currentTimeMillis > 300;
    }
}
